package mk.com.ldm.corepoint.implementation.client.lib.generators;

import java.util.HashMap;

import mk.com.ldm.corepoint.implementation.client.lib.custom.listview.ListView;
import mk.com.ldm.corepoint.implementation.client.lib.wrappers.widgets.ButtonWrapper;
import mk.com.ldm.corepoint.implementation.client.lib.wrappers.widgets.DateBoxWrapper;
import mk.com.ldm.corepoint.implementation.client.lib.wrappers.widgets.LabelWrapper;
import mk.com.ldm.corepoint.implementation.client.lib.wrappers.widgets.TextBoxWrapper;
import mk.com.ldm.corepoint.implementation.client.lib.wrappers.widgets.UploadWrapper;
import mk.com.ldm.corepoint.implementation.shared.FormRow;

import com.google.gwt.event.shared.HandlerManager;

public class WidgetFactory {

	private HashMap<String, Integer> widgetMap = new HashMap<String, Integer>();
	private HandlerManager eventBus;
	
	public WidgetFactory(HandlerManager eventBus){
		widgetMap.put("BT",0); //Button
		widgetMap.put("TB",1); //TextBox
		widgetMap.put("LB",2); //ListBox
		widgetMap.put("CB",3); //CheckBox
		widgetMap.put("RB",4); //RadioButton
		widgetMap.put("TA",5); //TextArea
		widgetMap.put("RT",6); //RichTextArea
		widgetMap.put("DB",7); //DateBox
		widgetMap.put("UD", 8); //Upload
		widgetMap.put("PT", 9); //PagingTable
		widgetMap.put("LL", 10); //Label
		widgetMap.put("LV", 11); //ListView
		
		this.eventBus = eventBus;
	}
	
	public BaseWidget getWidget(FormRow config, HandlerManager eventBus){
		Integer code = widgetMap.get(config.getInp());
		
		switch(code){
			case 0: return new ButtonWrapper(config, eventBus);
			case 1: return new TextBoxWrapper(config, eventBus);
			case 7: return new DateBoxWrapper(config, eventBus);
			case 8: return new UploadWrapper(config, eventBus);
			case 10: return new LabelWrapper(config);
			case 11: return new ListView(config, eventBus);
			default: return null; //Widget not found.
		}
			 
	}
	
}
